# coding=utf-8
"""
Author: Mr.夏末
@Function: 图文验证码破解
"""
import os
import time

from selenium import webdriver

# 创建浏览器对象
from class10.verify import Verify

driver = webdriver.Chrome()
# 添加隐式等待
driver.implicitly_wait(5)

# 打开网站
driver.get("http://47.105.110.138:8000/index.php/Home/user/login.html")
# 最大化浏览器
driver.maximize_window()

#ID定位
ele = driver.find_element('id','username')
# 操作元素:13800138006/2529085125@qq.com
ele.send_keys('2529085125@qq.com')

ele = driver.find_element('link text','淘宝网')
print(ele.get_attribute('outerHTML'))
# 部分文本
ele = driver.find_element("partial link text",'淘宝')
print(ele.get_attribute('outerHTML'))

# 输入密码
driver.find_element('xpath','//*[@id="password"]').send_keys('123456')
# 截取验证码图片
vimg = driver.find_element('xpath','//*[@id="verify_code_img"]')
vimg.screenshot('./verify.png')
# 获取验证码
verify = Verify('wuqingfqng','wuqing&fqng','904357')
# verify = Verify('17863087593','hzs123456','937288')
# 调用方法，获取验证码
ver = verify.get_verify('./verify.png')

# 输入验证码
driver.find_element('xpath','//*[@id="verify_code"]').send_keys(ver)

# 点击登录
driver.find_element('xpath','//*[@id="loginform"]/div/div[6]/a').click()

# 获取昵称
nickname = driver.find_element('xpath','//a[@class="red userinfo"]').text
print(nickname)
